<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>

        function sum ( a , b) {
            // 短路赋值   如果传参了，传几就是几，如果没有传参默认是0
            a = a || 0 ;
            b = b || 0 ; 
            return a + b 
        }

        console.log(sum(1 , 2)) ;   // 1 + undefined  // NaN
        console.log(sum(1));
        console.log(sum()) ;  // NaN   // 0



        function rand(min , max) {
            return parseInt(Math.random() * (max - min)) + min ;
        }

        function code(n) {
            // 默认产生4位数的验证码
            n = n || 4 ;

            var res = '' ;  // 结果是一个字符串
            for(var i = 0 ; i < n ; i++) {
                res += rand(0 , 10) ;
            }
            return res ;
        }


        code() ;  // 
        





    </script>
    
</body>
</html>